package com.fdb.smcts.redis;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.StringRedisTemplate;

import com.alibaba.fastjson.JSONObject;

public class Main {
	private List<String> list = new ArrayList<String>();
	
	public static void main(String[] args) throws IOException, InterruptedException {
		ClassPathXmlApplicationContext classPathXmlApplicationContext = 
				new ClassPathXmlApplicationContext("classpath:spring/spring-redis-standalone.xml");
		classPathXmlApplicationContext.refresh();
		classPathXmlApplicationContext.start();
		
		StringRedisTemplate template = classPathXmlApplicationContext.getBean(StringRedisTemplate.class);
		// 设置键：test1 值：calue的键值对到Redis中，20秒过期
		template.opsForValue().set("test1", "calue", 20, TimeUnit.SECONDS);
		// 休息20s
		TimeUnit.SECONDS.sleep(20);
		// 此时键应该过期
		if (template.opsForValue().get("test1") == null) {
			System.out.println("已过期");
		} else {
			System.out.println("不可能！");
		}
		System.in.read();
		classPathXmlApplicationContext.close();
	}

	public List<String> getList() {
		return list;
	}
	
	public void setList(List<String> list) {
		this.list = list;
	}
}
